map_jc_00 = readOGR(‘data/maps/tract2000’, layer = “tr21_d00”, GDAL1_integer64_policy = TRUE, stringsAsFactors = FALSE, verbose = FALSE)
map_jc_00\(TRACT <- as.numeric(map_jc_00\)TRACT)
This map shows the change in the percentage of residents for each census tract. Data are five-year averages from 2008 and 2014.
## [1] 4.075104 4.000892 3.985371 4.141890 4.161778 4.204630 4.214976
## [8] 4.108160 4.142172 4.195136 4.102059 4.360335 4.373332 4.053844
## [15] 4.046785 4.106525 4.121119 5.142077 4.704795 4.278122 4.130230
## [22] 4.120311 4.300300 4.193726 4.420506 4.541269 4.337842 4.736963
## [29] 4.173651 4.133581 4.354862 4.369219 4.192671 4.395541 4.389152
## [36] 3.941395 3.735355 4.218926 4.178198 4.148184 3.993816 3.955275
## [43] 4.191756 5.128710 3.770894 3.904811 3.896253 3.865138 4.162810
## [50] 3.828271 4.121950 5.488429 NA 4.210695 4.169634 4.140003
## [57] 4.129598 4.201265 4.244187 4.201463 4.248635 4.296525 4.091932
## [64] 4.388074 4.180676 4.195719 4.205068 4.057348 4.243907 4.270836
## [71] 4.072411 4.231113 4.059936 4.129124 4.305287 4.160617 4.110324
## [78] 4.430158 4.299407 5.898710 4.528342 4.703251 4.656774 4.906375
## [85] 5.250997 5.002339 4.471419 4.463386 4.630192 4.455917 4.516828
## [92] 4.317960 3.981264 3.986908 4.069107 4.184054 4.221752 2.009187
## [99] 4.150458 4.160784 4.696115 4.209546 4.073380 4.403895 4.037474
## [106] 4.136164 3.496196 3.888830 4.162168 3.673765 4.334768 4.178714
## [113] 4.179374 4.388373 4.283187 4.324865 4.202705 4.130446 4.107781
## [120] 4.349890 4.650194 4.579322 4.798220 4.275132 4.342681 4.446496
## [127] 4.574243 4.534185 4.680542 5.186421 5.301264 5.186300 4.723853
## [134] 4.761705 4.934424 5.510155 5.444242 4.475147 4.403918 3.647998
## [141] 0.000000 4.399022 4.115843 4.352099 4.159922 4.351904 4.036591
## [148] 4.176806 4.392168 4.494167 4.168438 4.357128 4.068170 4.327258
## [155] 4.373884 4.601587 4.117539 4.134790 4.544618 4.263086 4.392097
## [162] 4.176892 4.307467 4.471645 4.419702 4.180165 4.315309 4.249905
## [169] 4.238440 4.218360 4.309735 4.117637 4.253096 4.596219 4.126434
## [176] 4.191331 4.317557 4.291697 4.495656 4.494745 4.367868 4.095351
## [183] 4.354373 4.402156 3.787806 4.030746 4.307206 4.015683 4.126660
## [190] NaN 4.114165
va = “population_change” name = “” units = “Percent” map_style = “divergent” legend_title = “” palette = “” reverse = F
#renames var for use with the ’\(' operator map_jc@data\)var <- map_jc@data[[“population_change”]]
#concatenate third line of text for tract labels using units parameter if(units == “Percent”){ map_jc@data$l_line3 <- paste(name, “:”, round(map_jc@data$var, 2),“%”, sep = “”) } if(units == “Dollars”){ map_jc@data$l_line3 <- paste(name, “: \(", prettyNum( signif(map_jc@data\)var, 3), big.mark =”,“, preserve.width =”none" ), sep = “”) } if(units == “minutes”){ map_jc@data$l_line3 <- paste(name, “:”, round(map_jc@data$var, 2)," minutes“, sep =”“) } if(units ==”people“){ map_jc@data$l_line3 <- paste(name,”: “, round(map_jc@data$var, 2),” people“, sep =”“) } if(units ==”none“){ map_jc@data$l_line3 <- paste(name,”: “, round(map_jc@data$var, 2), sep =”“) }
#combine lines of text into full formatted label labels <- sprintf(“%s
%s
%s”, map_jc@data$l_line1, map_jc@data$l_line2, map_jc@data$l_line3 ) %>% lapply(htmltools::HTML)
labels[[190]] <- htmltools::HTML(sprintf(“%s
%s
%s”, “Tract #: 980000”, “Louisville International Airport”, “No residents” ) )
#Define palette using map_style parameter if(map_style == “sequential” | map_style == “Sequential”){ col_palette = “BuPu” } if(map_style == “divergent” | map_style == “Divergent”){ col_palette = “RdYlGn” }
#pal <- brewer.pal(11, col_palette) neg <- colorNumeric( palette = “OrRd”, domain = subset(map_jc@data, var <= 0)\(var ) pos <- colorNumeric( palette = "Greens", domain = subset(map_jc@data, var > 0)\)var )
pal <- colorNumeric( palette = “Greens”, domain = map_jc@data$var )
pal <- function(x){ this <- pos(x) that <- neg(x)
color <- if_else(x > 0, this, that)
color <- replace_na(color, "#808080")
color
}
#Create map title using legend_title parameter if(units == “Percent”) { title_text <- paste(legend_title, “(%)”, sep = ‘’) } if(units == “Dollars”) { title_text <- paste(legend_title, “($)”, sep = ‘’) } if(units == “minutes”){ title_text <- paste(legend_title, “(minutes)”, sep = ‘’) } if(units == “people”){ title_text <- paste(legend_title, “(people)”, sep = ‘’) } if(units == “none”){ title_text <- legend_title }
#create map m <- leaflet(map_jc) %>% addTiles() %>% addPolygons(color = “#444444”, weight = 1, smoothFactor = 0.5, opacity = 1.0, fillOpacity = 0.5, fillColor = ~pal(var), label = labels, labelOptions = labelOptions( style = list(“font-weight” = “normal”, padding = “3px 8px”), textsize = “15px”, direction = “auto”)) %>% addLegend(pal = pal, values = ~var, opacity = 0.7, title = title_text, position = “bottomright”) m pal2(2000)
This map shows the percentage change in each county’s population relative to the change in the entire county’s population.




observe({ var <- input$variable
leafletProxy("map", data = map_data) %>%
addTiles() %>%
addPolygons(color = "#444444", weight = 1, smoothFactor = 0.5,
opacity = 1.0, fillOpacity = 0.5,
fillColor = ~pal(var),
#label = labels,
labelOptions = labelOptions(
style = list("font-weight" = "normal", padding = "3px 8px"),
textsize = "15px",
direction = "auto"))%>%
addLegend(pal = pal, values = ~var, opacity = 0.7, title = var,
position = "bottomright")
})

| Percent of City in Tract | Percent of Black Residents in Tract | Percent of Tract that is Black | Cumulative % of Black Residents | Cumulative % of All Residents |
|---|---|---|---|---|
| 1.0 | 3.3 | 72.2 | 3.3 | 1.0 |
| 0.7 | 3.1 | 94.7 | 6.4 | 1.7 |
| 0.9 | 3.0 | 65.8 | 9.4 | 2.6 |
| 0.7 | 2.5 | 76.0 | 11.9 | 3.3 |
| 0.4 | 1.9 | 95.2 | 13.8 | 3.7 |
| 0.4 | 1.9 | 95.7 | 15.7 | 4.1 |
| 0.5 | 1.9 | 85.8 | 17.6 | 4.6 |
| 0.8 | 1.9 | 51.7 | 19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